<!DOCTYPE HTML>
<html>
{include file="public:header_css"}
<body>
    <div class="page-container">
        <div action="" method="post" class="form form-horizontal" id="form-shops-add" enctype="multipart/form-data">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3" style="padding-left: 75px;">星期：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width: 150px;">
                    <select name="" class="select" id="week_day">
                        {foreach name="week_arr" item="val" key="key"}
                        <option value="{$key}" style="width:60%;">{$val}</option>
                        {/foreach}
                    </select>
                    </span>
                </div>
            </div>
            <div class="row cl" style="margin-top: 30px;">
                <label class="form-label col-xs-4 col-sm-3" style="padding-left: 75px;">时段：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width: 150px;">
                    <select name="" class="select" id="period_id">
                        {foreach name="period_list" item="val" key="key"}
                        <option value="{$val['id']}" style="width:60%;">{$val['time']}</option>
                        {/foreach}
                    </select>
                    </span>
                </div>
            </div>
            <div class="row cl" style="margin-top: 30px;">
                <label class="form-label col-xs-4 col-sm-3" style="padding-left: 75px;">具体班级：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width: 150px;">
                    <select name="" class="select" id="class_id">
                        {foreach name="class_list" item="val" key="key"}
                        <option value="{$val['class_id']}" style="width:60%;">{$val['class_name']}</option>
                        {/foreach}
                    </select>
                    </span>
                </div>
            </div>
            <div class="row cl" style="margin-top: 30px;">
                <label class="form-label col-xs-4 col-sm-3" style="padding-left: 75px;">选择教师：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box" style="width: 150px;">
                    <select name="" class="select" id="teacher_id">
                        {foreach name="teacher_list" item="val" key="key"}
                        <option value="{$val['teacher_id']}" style="width:60%;">{$val['teacher_name']}</option>
                        {/foreach}
                    </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <div class="col-9 col-offset-3"  style="margin-top: 50px">
                    <input type="hidden" value="{$course_id}" id="course_id">
                    <button class="btn btn-primary radius" type="submit" id="submit">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                    <a class="btn btn-warning radius" onclick="cancel()">&nbsp;&nbsp;取消&nbsp;&nbsp;</a>
                </div>
            </div>
        </div>
    </div>

{include file="public:footer_js"}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__STATIC__/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/laypage/1.2/laypage.js"></script>

<script type="text/javascript">

    //取消再次添加，并返回排课列表
    function cancel(){
        var  course_id = $('#course_id').val();
        parent.location.href = "{:url('course_arrange/index')}"+"?course_id="+course_id;
    }

    //异步提交
    $("#submit").click(function(){

        var week_day     = $("#week_day").val();
        var period_id    = $("#period_id").val();
        var class_id     = $("#class_id").val();
        var teacher_id   = $("#teacher_id").val();
        var course_id    = $("#course_id").val();

        //拼接星期和时间段和班级名
        var arrange_item1 = week_day+"&"+period_id+"&"+class_id;
        //拼接星期和时间段和课程
        var arrange_item2 = week_day+"&"+period_id+"&"+course_id;
        //拼接星期和时间段和教师
        var arrange_item3 = week_day+"&"+period_id+"&"+teacher_id;
        //拼接星期和时间段和班级名和教师
        var arrange_item4 = arrange_item1+"&"+teacher_id;

        //异步提交
        $.ajax({
            type:"POST",
            url:"{:url('collision_detection_again')}",
            data:{
                arrange_item1 : arrange_item1,
                arrange_item2 : arrange_item2,
                arrange_item3 : arrange_item3
            },
            async:true,
            success:function (res) {
                if(res.code === 0){
                    layer.msg(res.msg,{icon:5,time:2000});
                }else{
                    //新增数据
                    //异步提交
                    $.ajax({
                        type:"POST",
                        url:"{:url('add_again')}",
                        data:{
                            course_id      : course_id,
                            arrange_time   : JSON.stringify(arrange_item4)
                        },
                        async:true,
                        success:function (res) {
                            if(res.code === 0){
                                layer.msg(res.msg,{icon:5,time:2000});
                            }else{
                                layer.msg(res.msg,{icon:6,time:2000});
                                setTimeout(
                                    function(){
                                        parent.location.href = "{:url('course_arrange/index')}"+"?course_id="+res.data;
                                    },
                                    3000);
                            }
                        }
                    });
                }
            }
        });

    });
</script>
</body>

</html>